package com.lyf.scm.admin.domain.remote.allocationservice.facade;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageInfo;
import com.lyf.scm.admin.api.dto.DirectlyStoreDTO;
import com.lyf.scm.admin.api.dto.DirectlyStoreReturnDTO;
import com.lyf.scm.admin.domain.remote.allocationservice.DirectlyStoreRemote;
import com.lyf.scm.common.enums.ResponseMsg;
import com.rome.arch.core.clientobject.Response;
import com.rome.arch.core.exception.RomeException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * description:
 * 直营预测计划--门店Facade
 *
 * @author: haodong
 * @data: 2020/8/29 19:22
 */
@Service
@Slf4j
public class DirectlyStoreFacade {

    @Resource
    private DirectlyStoreRemote directlyStoreRemote;

    /**
     * 按条件查询直营预测计划
     *
     * @param directlyStore
     * @return
     */
    public PageInfo<DirectlyStoreReturnDTO> listPageBySelective(DirectlyStoreDTO directlyStore) {
        log.info("按条件查询直营预测计划入参:DirectlyStoreDTO:{}", JSON.toJSONString(directlyStore));
        Response<PageInfo<DirectlyStoreReturnDTO>> response = directlyStoreRemote.listPageBySelective(directlyStore);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    /**
     * 查询全渠道直营预测计划
     *
     * @param directlyStore
     * @return
     */
    public List<DirectlyStoreReturnDTO> listAllByCycles(DirectlyStoreDTO directlyStore) {
        log.info("查询全渠道直营预测计划入参:DirectlyStoreDTO:{}", JSON.toJSONString(directlyStore));
        Response<List<DirectlyStoreReturnDTO>> response = directlyStoreRemote.listAllByCycles(directlyStore);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    /**
     * 更新确认量
     *
     * @param directlyUpdateList
     * @param unitType
     * @return
     */
    public Boolean updateConfirm(List<DirectlyStoreDTO> directlyUpdateList, Long unitType) {
        log.info("更新确认量入参:DirectlyStoreDTO:{}", JSON.toJSONString(directlyUpdateList));
        Response<Boolean> response = directlyStoreRemote.updateConfirm(directlyUpdateList,unitType);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    /**
     * 导出
     * @param directly
     * @param type
     * @return
     */
    public List<DirectlyStoreReturnDTO> exportExcel(DirectlyStoreDTO directly, Integer type) {
        log.info("直营预测计划(门店)导出入参:DirectlyStoreDTO:{}", JSON.toJSONString(directly));
        Response<List<DirectlyStoreReturnDTO>> response = directlyStoreRemote.exportExcel(directly,type);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }

    public void delete(String opSign) {
        log.info("删除直营预测计划(门店):{}", JSON.toJSONString(opSign));
        directlyStoreRemote.delete(opSign);
    }

    public List<DirectlyStoreDTO> listByCondition(DirectlyStoreDTO directlyStore) {
        log.info("直营预测计划(门店)确认量入参:DirectlyStoreDTO:{}", JSON.toJSONString(directlyStore));
        Response<List<DirectlyStoreDTO>> response = directlyStoreRemote.listByCondition(directlyStore);
        if (!response.getCode().equals(ResponseMsg.SUCCESS.getCode())) {
            throw new RomeException(response.getCode(), response.getMsg());
        }
        return response.getData();
    }
}
